<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>人和人律师事务所管理系统v-1.0--工资管理页面</title>
<style type="text/css" media="all">
.allow-float {
	clear: none !important;
}  /* 允许该元素浮动 */
.stop-float {
	clear: both !important;
}  /* 阻止该元素浮动 */
.float-left {
	float: left;
	padding-left: 10px
} /*浮动到左边*/
</style>
<script type="text/javascript">
Ext.onReady(function(){

		//律师助理姓名列表STORE
		var lawyerAssiStore=new Ext.data.JsonStore({
		url:'LawyerAssiNamesRequest.jsj',
		totalProperty:'totalCount',
		root:'result',
		fields:["lawyerAssiId","lawyerAssiName"]
		})


		var searchWagePanel=new Ext.form.FormPanel({
		labelAlign:'right',
		title:'工资帐查询',
		labelSeparator:':',
		bodyStyle:'padding:5',
		frame:true,
		collapsible:true,
		height:100,
		width:window.screen.width-220,
		applyTo:'searchWageWin',

		items:[

			new  Ext.form.ComboBox({
			fieldLabel:'请选择律师助理',
			itemCls:'float-left',//向左浮动
			clearCls:'allow-float',//允许浮动
			store:new Ext.data.JsonStore({
			url:'LawyerAssiNamesRequest.jsj',
			totalProperty:'totalCount',
			root:'result',
			fields:["lawyerassiid","lawyerassiname"]
			}),
			valueField:'lawyerassiid',
			displayField:'lawyerassiname',
			forceSelection:true,
			emptyText:'请选择律师助理',
			hiddenName:'lawyerAss',
			editable:false,
			triggerAction:'all',
			id:'lawyerAssiName',
			name:'lawyerAssiName'
			}),

			new Ext.form.TextField({
			fieldLabel:'入资者',
			id:'enterWagePer',
			name:'enterWagePer',
			width:(window.screen.width-320)*0.18,
			itemCls:'float-left',
			clearCls:'allow-float',
			selectOnFocus:true,
			allowBlank:true
			}),

			new Ext.Button({
			text:'开始查询',
			iconCls:'search',
			cls:'float-left',//向左浮动
			handler : submitMsg
			})
		]
		})

		//查询处理函数
		function submitMsg(){
		//获得要查询的律师助理姓名与入资者的姓名
		var lawyerAssiName=Ext.getCmp("lawyerAssiName").getValue();
		var enterWagePer=Ext.getCmp("enterWagePer").getValue();

		//判断是否输入了条件
		if(lawyerAssiName==""&&enterWagePer=="")
		{
			Ext.MessageBox.alert("提示","请输入查询条件");
			return;
		}
		//判断输入是否违法
		if(lawyerAssiName!=""&&enterWagePer!=""){
			Ext.MessageBox.alert("提示","两条件只能二选一");
			return;
		}

		 store = new Ext.data.JsonStore({
		url:"SearchWageInfo.jsj?lawyerAssiName="+lawyerAssiName+"&enterWagePer="+enterWagePer,
		totalProperty: 'totalCount',
   	 	root: 'result',
		fields:["wageid","lawyassistantname","wagetime","wagebrief","wageincome","wagepayout","enterwageper"]
			});
		store.reload({
			params:{
				start:0,
				limit:5
				}
			});
		var colModel = new Ext.grid.ColumnModel([//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "记录时间",width: 100,  dataIndex: 'wagetime', sortable: true},
				{header: "收入金额", width: 100,dataIndex: 'wageincome', sortable: true},
				{header: "支出金额",width: 100, dataIndex: 'wagepayout', sortable: true},
				{header: "律师助理",width: 150, dataIndex: 'lawyassistantname', sortable: true},
				{header: "入资者",width: 150, dataIndex: 'enterwageper', sortable: true},
				{header: "工资摘要",width: 300, dataIndex: 'wagebrief', sortable: true}
				]);
				pagebar.bind(store);
				grid.getView().autoFill=true;
				grid.reconfigure(store,colModel);
					grid.getView().autoFill=true;
		grid.getView().refresh(true);
	}


	//存储器
		var store = new Ext.data.JsonStore({
	url:"WageInfoRequest.jsj",
	totalProperty: 'totalCount',
	root: 'result',
	fields:["wageid","lawyassistantname","wagetime","wagebrief","wageincome","wagepayout","enterwageper"]
			});
		store.load({
			params:{
				start:0,
				limit:5
				}
			});

	//获得用户权限
		var buttonDisabled=true;
	<%
	if((java.lang.Integer)session.getAttribute("popedomLevel")==1){
		%>
		buttonDisabled=false;
	<%
	}
	%>

		//创建工具栏组件
		var toolbar = new Ext.Toolbar([
			{text : '工资详细信息'},
			'-',
			{
			text:'查看工资余额',
			iconCls:'search',
			handler:function(btn,pressed){
			lookWageLeft();
			}
			},
			'-',
			{
			text:'增加一条工资记录',
			iconCls:'add',
			disabled:buttonDisabled,
			handler:function(btn,pressed){
			addWageInfo();
			}
			},

			'-',
			{
			text:'修改',
			iconCls:'option',
			handler:function(btn,pressed){
			modifyWageFun();
			}
			}
		]);


				//修改工资帐面板
		var modifyWagePanel;
		//修改工资帐窗口
		var modifyWageWin;
		//修改工资帐函数
		function modifyWageFun(){
				//获取要修改的一条记录
			var record=grid.getSelectionModel().getSelected();
			//如果没有选择用户
			if(!record){
				Ext.MessageBox.alert("修改操作","请选择要修改的一项！");
			}else{
				//修改工资帐窗口
				modifyWageWin=new Ext.Window({
					width:500,
					height:250,
					closeAction:'hide',
					layout:'fit',
					plain:true,
					title:'修改工资信息窗口',
					items:modifyWagePanel
				});
				//显示窗口
				modifyWageWin.show();
				//加载原数据
				 Ext.getCmp("mwageId").setValue(record.get("wageid"));
 				 Ext.getCmp("mwageTime").setValue(record.get("wagetime"));
       			 Ext.getCmp("mwageIncome").setValue(record.get("wageincome"));
       			 Ext.getCmp("mwagePayout").setValue(record.get("wagepayout"));
       			 Ext.getCmp("mwageLawyerAssis").setValue(record.get("lawyassistantname"));
       			 Ext.getCmp("menterWagePer").setValue(record.get("enterwageper"));
       	    	 Ext.getCmp("mwageBrief").setValue(record.get("wagebrief"));
			}
		}

		//修改工资帐信息面板
		 modifyWagePanel=new Ext.form.FormPanel({
		 		labelAlign:'right',
		 		buttonAlign:'center',
		 		closeAction:true,
		 		labelWidth:100,
		 		frame:true,
		 		bodyStyle:'padding:5px 5px 0',
		 		waitMsgTraget:true,
		 		defaults:{
		 			width:250
		 		},
		 		defaultType:'textfield',
		 		items:[
				 	{
				 		xtype:'hidden',
			            name :'mwageId',
			            id :'mwageId',
				    },
				    {
			            fieldLabel : '计入时间',
			            name :'mwageTime',
			            id :'mwageTime',
			            allowBlank :false
				    },
				    {
			            fieldLabel : '收入金额',
			            name :'mwageIncome',
			            id :'mwageIncome',
			            allowBlank :false
			        },
			        {
			            fieldLabel : '支出金额',
			            name :'mwagePayout',
			            id :'mwagePayout',
			            allowBlank :false
			        },
			        {
			            fieldLabel :'律师助理',
						id :'mwageLawyerAssis',
						name :'mwageLawyerAssis',
						allowBlank :false
			        },
			        {
			            fieldLabel :'入资者',
						id :'menterWagePer',
						name :'menterWagePer',
						allowBlank :false
			        },
			        {
			            fieldLabel :'工资摘要',
						id :'mwageBrief',
						name :'mwageBrief',
						allowBlank :false
			        }
		 		],

		 buttons : [ {
            text : '修改',
            disabled : false,
            handler : function() {
                if (modifyWagePanel.form.isValid()) {
                    modifyWagePanel.form.submit( {
                        url : 'ModifyWageInfo.jsj',
                        success : function(from, action) {
                        Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyWageWin.hide();
                        },
                        failure : function(form, action) {
                           Ext.MessageBox.alert('更新结果', action.result.message);
                            store.load( {
                                params : {
                                    start : 0,
                                    limit : 5
                                }
                            });
                            modifyWageWin.hide();
                        },
                        waitMsg : '正在保存数据，稍后...'
                    });
                } else {
                    Ext.Msg.alert('信息', '请填写完成再提交!');
                }
            }
        }, {
            text : '取消',
            handler : function() {
                modifyWageWin.hide();
            }
        }]
		 })


		//增加工资记录窗口
var addWageWindow;
//增加工资记录面板
var addWageForm;
 //增加工资记录函数
function addWageInfo(){
	addWageWindow=new Ext.Window({
		title:'增加一条工资记录',
		width:550,
		height:310,
		layout:'fit',
		closeAction:'hide',
		resizable:'false',
		//内嵌面板
		items:addWageForm
	});
	//显示窗口
	addWageWindow.show();
}

//增加工资记录面板
	addWageForm=new Ext.form.FormPanel({
	labelAlign:'right',
	buttonAlign:'center',
	frame:true,
	labelWidth:180,
	defaults:{
		width:200
	},
	items:[
	{
			xtype:'datefield',
			fieldLabel:'时间',
			format:'Y-m-d',
			name:'wageInfoTime',
			allowBlank:false
		},

	new  Ext.form.ComboBox({
			fieldLabel:'请选择律师助理',
			store:new Ext.data.JsonStore({
			url:'LawyerAssiNamesRequest.jsj',
			totalProperty:'totalCount',
			root:'result',
			fields:["lawyerassiid","lawyerassiname"]
			}),
			valueField:'lawyerassiid',
			displayField:'lawyerassiname',
			forceSelection:true,
			emptyText:'请选择律师助理',
			hiddenName:'lawyerAsName',
			editable:false,
			triggerAction:'all',
			id:'lawyerAssiNames',
			name:'lawyerAssiNames'
			}),
	{
		xtype:'textfield',
		fieldLabel:'收入金额（非入资金，填0）',
		name:'wageIncome',
		allowBlank:false
	},
	{
		xtype:'textfield',
		fieldLabel:'支出金额（非发工资，填0）',
		name:'wagePayout',
		allowBlank:false
	},
	{
		xtype:'textfield',
		fieldLabel:'入资者(所入资，填所里)',
		name:'enterWagePerson',
		value:'非入资',
		allowBlank:false
	},
	{
		xtype:'textarea',
		fieldLabel:'工资摘要',
		name:'wageBrief',
		allowBlank:false
	},
	{
		xtype:'textfield',
		inputType:'password',
		fieldLabel:'领工资签名(非领工资不填)',
		name:'lawyerAssSign',
		allowBlank:true
	}
	],
	buttons:[{
	text:'确认',
	handler:function(){
		var lawyerAssiNames=Ext.getCmp("lawyerAssiNames").getValue();
		//判断是否选择了律师助理
		if(lawyerAssiNames==""){
		Ext.MessageBox.alert('提示','请选择律师助理！');
		return;
		}
			if(addWageForm.form.isValid()){
				addWageForm.form.submit({
				url:'AddWageInfo.jsj',
				success:function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					addWageWindow.hide();
				},
				failure: function(form,action){
					Ext.MessageBox.alert('结果',action.result.message);
					//刷新数据
					store.load({
					params:{
					start:0,
					limit:5
					}
					});
					addWageWindow.hide();
				},
				waitMsg:'正在保存数据，稍后...'
				});
			} else {
				Ext.Msg.alert('信息', '请填写完成再提交!');
			}
		}
		},{
		 text:'取消',
		 handler:function(){
		 	addWageWindow.hide();
		 }
		}]
	})



	//查看工资余额窗口
var lookWageWindow;
//查看工资余额面板
var lookWageForm;
 //查看工余额函数
function lookWageLeft(){
	lookWageWindow=new Ext.Window({
		title:'查看工资余额',
		width:300,
		height:140,
		layout:'fit',
		closeAction:'hide',
		resizable:'false',
		//内嵌面板
		items:lookWageForm
	});
	//显示窗口
	lookWageWindow.show();
}

//查看工资余额面板
	lookWageForm=new Ext.form.FormPanel({
	labelAlign:'right',
	buttonAlign:'center',
	frame:true,
	labelWidth:80,
	defaults:{
		width:140
	},
	items:[
	new  Ext.form.ComboBox({
			fieldLabel:'律师助理',
			store:new Ext.data.JsonStore({
			url:'LawyerAssiNamesRequest.jsj',
			totalProperty:'totalCount',
			root:'result',
			fields:["lawyerassiid","lawyerassiname"]
			}),
			valueField:'lawyerassiid',
			displayField:'lawyerassiname',
			forceSelection:true,
			emptyText:'请选择律师助理',
			hiddenName:'lawyerAsName2',
			editable:false,
			triggerAction:'all',
			id:'lawyerAssiName2',
			name:'lawyerAssiName2'
			}),
	{
		xtype:'textfield',
		fieldLabel:'工资余额',
		id:"wageLeft",
		name:'wageLeft',
		allowBlank:true
	}
	],
	buttons:[{
	text:'确认',
	handler:function(){
			if(lookWageForm.form.isValid()){
				lookWageForm.form.submit({
				url:'LookWageLeft.jsj',
				success:function(form,action){
				Ext.getCmp("wageLeft").setValue(action.result.message);
				},
				failure: function(form,action){
				Ext.getCmp("wageLeft").setValue(action.result.message);
				},
				waitMsg:'正在发送请求，稍后...'
				});
			} else {
				Ext.Msg.alert('信息', '请填写完成再提交!');
			}
		}
		},{
		 text:'取消',
		 handler:function(){
		 	lookWageWindow.hide();
		 }
		}]
	})




		//分页工具栏
		var pagebar = new Ext.PagingToolbar({
			store : store,
			pageSize : 5,
			displayInfo : true,
			displayMsg : '第 {0} ~ {1} 条 共 {2} 条',
			emptyMsg : '当前没有记录'
		});

			//创建选择模式对象
	var cb = new Ext.grid.CheckboxSelectionModel()
	//创建Grid表格组件
	var grid = new Ext.grid.GridPanel({
			renderTo : 'wage-detail-info',
			frame : true,
			tbar : toolbar,
			bbar : pagebar,
			trackMouseOver:true, //鼠标特效
			loadMask: true,    //是否显示正在加载
			store : store,
			height : 320,
			width : window.screen.width-220,
			stripeRows : true,
			autoScroll : true,
			viewConfig : {autoFill : true},
			sm : cb,
			columns: [//配置表格列
				new Ext.grid.RowNumberer({
					header : '行号',
					width : 40
				}),
				cb,
				{header: "记录时间",width: 100,  dataIndex: 'wagetime', sortable: true},
				{header: "收入金额", width: 100,dataIndex: 'wageincome', sortable: true},
				{header: "支出金额",width: 100, dataIndex: 'wagepayout', sortable: true},
				{header: "律师助理",width: 100, dataIndex: 'lawyassistantname', sortable: true},
				{header: "入资者",width: 100, dataIndex: 'enterwageper', sortable: true},
				{header: "工资摘要",width: 100, dataIndex: 'wagebrief', sortable: true}
				]
		});
})


</script>
</head>

<body>
<table>
	<tr>
		<td>
		<div id='searchWageWin' style="margin: 8px 8px 4px 8px"></div>
		</td>
	</tr>
</table>
<div id='wage-detail-info' style="margin: 4px 8px 8px 8px"></div>
</body>
</html>